Skip to main content

Create an Entity

Overview

This document describes the procedure to create an entity in any work system using the SyncNow DevOps Gate. We provide Groovy scripts for Jenkins, or you can copy and paste cURL commands from our user interface in the DevOps Gate project configuration.

Overview

Usage Examples

  1. Creating a bug when automated testing fails.
  2. Creating a bug when a security vulnerability is found.
  3. Creating a service ticket when an incident is identified in another system.

Creating an Entity

This procedure creates an entity according to the mapping definition. SyncNow will update an existing entity if it has the same title/summary or matches a defined filter.

Create An Entity

Request

The request URL should include the system ID, which can be copied from the DevOps Process definition page.

POST /api/v1.0/DevOpsGate/Enrich/{DevOpsProjectID}?action=create

The payload contains the parameters as defined in the DevOps Gate Process and their values. Below are the parameters defined for the example request.

ParameterDescription
Param1…ParamXParameters as defined in the DevOps Gate per entityType mapping
subProjectThe target work system project as defined in the DevOps Gate Process. Work systems for publishing can be limited through SyncNow DevOps Process configuration
entityTypeThe entity to be created
CreateIfEntityDoesNotExistByTitleOtherwiseUpdateWhether to create an entity if found a similar one with the same title
[
  {
    "fields": [
      {
        "key": "Param1",
        "value": "string"
      },
      {
        "key": "Param2",
        "value": "string"
      },
      {
        "key": "Param3",
        "value": "string"
      }
    ],
    "subProject": "MyProject",
    "entityType": "Bug",
    "CreateIfEntityDoesNotExistByTitleOtherwiseUpdate": "false"
  }
]

Response

SyntaxDescription
SystemIDThe system where the entities were created
EntitiesIDThe IDs of the entities created
ErrorErrors that occurred during the creation process
WarningWarnings that occurred during the creation process
 {
    "updatedEntitiesID": [
        {
            "systemID": "10",
            "entityKeys": [
                "CLS-3938"
            ]
        }
    ],
    "errors": [],
    "warnings": []
}

Jenkins Groovy Script

Below is a Groovy code example that creates an entity with SyncNow DevOps Gate.

@NonCPS
def getCommentsString() {
    def list = []
    def changeLogSets = currentBuild.changeSets
    for (int i = 0; i < changeLogSets.size(); i++) {
        def entries = changeLogSets[i].items
        for (int j = 0; j < entries.length; j++) {
            def entry = entries[j]
            if (entry.msg != null) {
               list.add("""${entry.commitId} on ${new Date(entry.timestamp)}: ${entry.msg.replaceAll("[\n\r]", " ")}""")
            }
        }
    }
    return list.join(',')
}

pipeline {
    agent any

    stages {
        stage('Clone') {
            steps {
                echo 'Clone Code'
            }
        }
        stage('Version') {
            steps {
                echo 'Version'
            }
        }
        stage('Test') {
            steps {
                echo 'Test'
            }
        }
        stage('Build') {
            steps {
                echo 'Build'
            }
        }
        stage('Publish') {
            steps {
                echo 'Publish'
            }
        }
        stage('Notify SyncNow') {
            steps {
                echo 'Notify'
                echo "Job Name is ${JOB_NAME}, Build ID is ${env.BUILD_ID}"
                script {
                    def commits = getCommentsString()
                    def payload = """
[
 {
  "fields": [
   {
    "key": "Param1",
    "value": "string"
   },
   {
    "key": "Param2",
    "value": "string"
   },
   {
    "key": "Param3",
    "value": "string"
   }
  ],
  "subProject": "MyProject",
  "entityType": "Bug"  
 }
]
                    """
                    // Create entities and update entities from commit. Result in format for adding attachments
                    def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', authentication: 'SyncNow', requestBody: "${payload}", url: "https://<SyncNowBaseURL>/api/v1.0/app/DevOpsGate/Enrich/<DevOpsProjectID>?action=create"

                    println("Status: ${response.status}")
                    println("Content: ${response.content}")
                }
            }
        }
    }
}

Step-by-Step Instructions

Example: Create If… and Update an Entity Action

  1. Create a DevOps Gate Process.
  2. Navigate to the Mapping Entities page.
  3. Navigate to the Mapping Options page for specific entity mappings.

Navigate To Mapping Page

  1. Add filters. In the example below, a filter by Status is added.

Duplicate Detection: Entity names are always checked by their summary/title. If an entity with the same name/title and type is found, it will be updated.

Filter Entities For Update

  1. Go to the DevOps Gate Process Configuration and press the How It Works link.

DevOps Gate Configuration

  1. Select Create & Update Entities from Commits.

How It Works

  1. Copy the cURL command.

Copy cURL

  1. Paste it into a command line. Set the correct sub-project where the entity will be created and execute.

Paste Into Command Line

  1. Change the content of the fields as needed and execute again. A new entity will be created with information from both DevOps Gate calls.

New Entity Created

  1. Change the status of the entity.

Change Status

  1. Execute the cURL command again. A new entity will be created.

cURL Execution

Test Create Action